// pages/center/collection/collection.js
var api = require('../../utils/api.js')
var app = new getApp()
let leftHeight = 0,
  rightHeight = 0; //分别定义左右两边的高度
let query;
var app = new getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH: 0,
    isIphoneX: false,
    path:api.path,
    select: [],
    currentTab: 0,
    swiperRPXHeight: 0,
    current:0,
    brandArr:[],
    content:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
    this.getCountHeight()
  },
  getCountHeight(){
    let isIphoneX = app.globalData.isIphoneX
    if (isIphoneX) {
      this.setData({
        isIphoneX
      })
    }
    this.setData({
      navH: app.globalData.navHeight
    })
  },
  swiperChange(e){
    this.setData({
      current:e.detail
    })
  },
  goto(e){
    let index = e.detail
    let item  = this.data.brandArr[index]
    if(item.source==2){
      wx.navigateTo({
        url: '/pages/index/detail/detail?url='+item.url,
      })
    }else{
      wx.navigateTo({
        url: './detail/detail?id='+item.id,
      })
    }
  },
  getData(id){
    let params={
      page:1,
      size:999,
      id
    }
    let url = ''
    if(id){
      url = 'article_classfiy'
    }else{
      url = 'article_info'
    }
    api.post(url,params).then(res => {
      if (res.code == 200) {
        this.setData({
          content: res.data
        })
        let brandArr=[]
        res.data.top_article_arr.forEach(ele=>{
          brandArr.push({
            thumb:ele.thumb,
            source:ele.source,
            url:ele.url,
            id:ele.id
          })
        })
        this.setData({
          brandArr
        })
        if(!id){
          this.setData({
            select:res.data.classfiy_arr
          })
        }
      }
    })
  },
  toDetail(e){
    let item = e.currentTarget.dataset.item
    if(item.source==1){
      wx.navigateTo({
        url: './detail/detail?id='+item.id,
      })
    }else{
      wx.navigateTo({
        url: '/pages/index/detail/detail?url='+item.url,
      })
    }
    
  },
  selectList(event) {
    let index = event.currentTarget.dataset.index
    this.setData({
      currentTab: index
    })
    let id = this.data.select[index].id
    this.getData(id)
  },
  changeSelect(event) {
    this.setData({
      currentTab: event.detail.current
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      // imageUrl: '../../../imgs/index/share.jpg',
      // title: app.globalData.shareTitle,
      // path: '/pages/index/index'
    }
  }
})